Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should solve integer overflows in SAPT code #619

Merged
merged 2 commits into from
Feb 17, 2017
Merged

Should solve integer overflows in SAPT code #619

merged 2 commits into from
Feb 17, 2017

Conversation

jgonthier
Copy link
Member

@jgonthier jgonthier commented Feb 14, 2017

Description

Substitute some int by size_t, and introduces (size_t) casts wherever multiplication of integers seemed problematic.

Todos

  • Developer Interest
    • Integer declarations in all .h files in libsapt_solver have been examined and the ones that could potentially generate overflows were converted to size_t. Probably some overkill there.
    • Searched the whole source in libsapt_solver for a regex representing 4 variables being multiplied, to find all the occvirocc*vir that are bound to overflow. Added (size_t) cast for those that were missing it

Questions

  • This originated in a problem reported by a user on the forum. I can't run Psi4 on good enough hardware to actually test the patch on a large system. Anyone want to give it a try ? Or do we let the user test it ?

Status

  • Ready to go

Should prevent integer overflow. May not be exhaustive though.
Copy link
Member

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jerome, these look great.

Im not sure were we could fish up a box that has the ~130GB of space to test things out. We could just try banging on virtual memory.

@@ -620,7 +620,7 @@ void SAPT2::ijkl_to_ikjl(double *tARAR, int ilength, int jlength, int klength,

for(int i=0; i<ilength; i++) {
for(int l=0; l<llength; l++) {
long int ijkl = i*jlength*klength*llength + l;
long int ijkl = (long int)i*jlength*klength*llength + l;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might remember wrong, but don't you need to also cast jlength, klength and llength, since the order of evaluation isn't guaranteed...? What this is doing is typecasting i to long int, but jlengthklengthllength is still int and might overflow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, the compiler should promote all of the operands to long int before the multiplication takes place.

@@ -240,7 +240,7 @@ void SAPT2p::r_ccd_prep(const char *TARBS, const char *ARBS, const char *CA_RBS,

double **tARBS = block_matrix(occA*virA,occB*virB); //!

C_DCOPY(occA*virA*occB*virB,&(vARBS[0][0]),1,&(tARBS[0][0]),1);
C_DCOPY((size_t)occA*virA*occB*virB,&(vARBS[0][0]),1,&(tARBS[0][0]),1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.

@dgasmith
Copy link
Member

@jgonthier These are good changes regardless, so pulling them in now. If it turns out it didn't fix the problem we can always go back in later.

@dgasmith dgasmith merged commit 44786bd into psi4:master Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants